/** 工单用购买渠道与业务类型关系配置表 */
import request from '@/utils/request'

// 查询所有
export function getChannelBusinessRelAll() {
  return request({
    method: 'GET',
    url: `/call-center/api/v2/channelBusinessRelation/`
  })
}

/** 新增
 * @param {String} businessType 一级业务类型code
 * @param {String} businessTypeName 一级业务类型name
 * @param {String} businessTypeTwo 二级业务类型Code
 * @param {String} businessTypeTwoName 二级业务类型Name
 * @param {String} channel 渠道code
 * @param {String} channelName 渠道名称
 */
export function saveChannelBusinessRel(data) {
  return request({
    method: data.id ? 'PUT' : 'POST',
    url: '/call-center/api/v2/channelBusinessRelation',
    data
  })
}

/** 删除
 * @param {String} id 关联ID
 */
export function deleteChannelRel(id) {
  return request({
    method: 'DELETE',
    url: `/call-center/api/v2/channelBusinessRelation/${id}`
  })
}

/** 批量删除
 * @param {Array} ids 关联ID集合
 */
export function deleteBatch(ids) {
  return request({
    method: 'DELETE',
    url: `/call-center/api/v2/channelBusinessRelation/deleteBatch`,
    data: ids
  })
}

/**
 * 根据购买渠道查询一级业务类型
 */
export function searchBusinessByChannel(channelCode) {
  return request({
    method: 'GET',
    url: `/call-center/api/v2/channelBusinessRelation/queryBusiness/${channelCode}`
  })
}

/**
 * 根据购买渠道+一级业务类型获取二级业务类型
 */
export function searchBusinessTwoByChannel({ channelCode, businessType }) {
  return request({
    method: 'GET',
    url: `/call-center/api/v2/channelBusinessRelation/queryBusinessTwo/${channelCode}/${businessType}`
  })
}
